import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/req/other/req_other.dart';
import 'package:flutter_changdian_football/config/enum/load_state.dart';
import 'package:flutter_changdian_football/model/other/help_model.dart';
import 'package:flutter_changdian_football/widget/toast/custom_toast.dart';
import 'package:get/get.dart';

class UsingHelpController extends GetxController {

  @override
  void onInit() {
    super.onInit();

    initData();
  }

  LoadState state = LoadState.loading;
  List<HelpModel> helpList = [];

  initData() async {
    var resp = await ReqOther.helpQuestion();
    if (resp.status == Status.completed) {
      if (resp.data['code'] == '200') {
        helpList.clear();
        for (int i = 0; i < resp.data['data'].length; i++) {
          helpList.add(HelpModel.fromJson(resp.data['data'][i]));
        }

        if (helpList.isNotEmpty) {
          state = LoadState.success;
        } else {
          state = LoadState.empty;
        }

        update();
      } else if (resp.data['code'] == 401) {
      } else {
        CustomToast.showTextToast('${resp.data['msg']}');
        state = LoadState.error;
        update();
      }
    } else {
      state = LoadState.network;
      update();
    }
  }

  changeIsShow(int index) {
    if (helpList[index].isShow == true) {
      helpList[index].isShow = false;
    } else {
      helpList[index].isShow = true;
    }
    update();
  }

}